package com.easyedu.dean.controller;

import com.easyedu.core.entity.po.Institute;
import com.easyedu.core.util.R;
import com.easyedu.dean.entity.dto.request.ReqInstitute;
import com.easyedu.dean.interfaces.InstituteDeleteGroup;
import com.easyedu.dean.interfaces.InstituteGroup;
import com.easyedu.dean.service.InstituteService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lmr</ br>
 * 学院管理
 **/
@RestController
@RequestMapping("/dean")
public class InstituteController {

    private final InstituteService instituteService;

    public InstituteController(InstituteService instituteService) {
        this.instituteService = instituteService;
    }

    /**
     * 功能描述：查询学院及专业信息
     *
     * @return
     */
    @GetMapping("/institute")
    public R getInstitute() {
        List<Institute> institute = instituteService.getInstitute();
        return R.ok().data(institute);
    }

    /**
     * 功能描述: 新增学院及专业信息
     *
     * @param reqInstitute 1 学院机构 Persistant Object
     * @return : com.easyedu.api.util.R
     **/
    @PostMapping("/institute")
    public R createInstitute(@RequestBody @Validated({InstituteGroup.class, InstituteDeleteGroup.class}) ReqInstitute reqInstitute) {
        instituteService.createInstitute(reqInstitute);
        return R.ok().message("新增学院信息成功");
    }

    /**
     * 功能描述: 删除学院及专业信息
     *
     * @param reqInstitute 1 学院机构 Persistant Object
     * @return : com.easyedu.api.util.R
     **/
    @DeleteMapping("/institute")
    public R deleteInstitute(@RequestBody @Validated({InstituteDeleteGroup.class}) ReqInstitute reqInstitute) {
        instituteService.deleteInstitute(reqInstitute);
        return R.ok().message("删除学院信息成功");
    }
}
